from CvPythonExtensions import *
from WriterUtils import *

import CvScreenEnums
import CvUtil
import CvConfigParser
import CvPath
import os
import os.path
import Popup as PyPopup
import shutil 

# globals
gc = CyGlobalContext()
ArtFileMgr = CyArtFileMgr()
localText = CyTranslator()

# Change this to change the location where the resulting CIV4CivicInfos.xml file 
# will be saved. So if the default value is left to "Test" then the 
# CIV4CivicInfos.xml file would be written in a directory called "Test" inside 
# of the Tech Tree Editor mod folder.
# Default value is Test
g_strSaveDirectoryLocation = "Test"

# Change the value to false if the assets directory structure shouldn't be 
# created at the directory specified by the "Save Directory Location".
# Default value is True
g_bCreateAssetHierarchy = True

# Change the value to false if the changes made shouldn't be saved into the 
# assets directory for the tech editor. Changing it to false will require 
# manual copying of the saved files from the directory specified in the 
# "Save Directory Location" configurable option to the editor's asset directory 
# when wanting to edit existing mod files.
# Default value is True
g_bSaveChangesInEditorAssetsDirectory = True

def loadConfigurationValues():
	global g_strSaveDirectoryLocation
	global g_bCreateAssetHierarchy
	global g_bSaveChangesInEditorAssetsDirectory
	
	config = CvConfigParser.CvConfigParser("ViSa_v3.ini")

	if(config != None):
		g_strSaveDirectoryLocation = config.get("Tech Tree Editor", "Save Directory Location", "Test")
		g_bCreateAssetHierarchy = config.getboolean("Tech Tree Editor", "Create Asset Hierarchy", True)
		g_bSaveChangesInEditorAssetsDirectory = config.getboolean("Tech Tree Editor", "Save Changes In Editor Assets Directory", True)

		if(len(g_strSaveDirectoryLocation) == 0):
			g_strSaveDirectoryLocation = "Test"
			
class CivicInfoWriter:
		
	def __init__(self):
		loadConfigurationValues()


	def isYieldModifiersDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objCivicInfo.getYieldModifier(iI) > 0):
				return true

		return false

	def isCapitalYieldModifiersDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objCivicInfo.getCapitalYieldModifier(iI) > 0):
				return true

		return false

	def isTradeYieldModifiersDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objCivicInfo.getTradeYieldModifier(iI) > 0):
				return true

		return false
						
	def isCommerceModifiersDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objCivicInfo.getCommerceModifier(iI) > 0):
				return true

		return false
						
	def isCapitalCommerceModifiersDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objCivicInfo.getCapitalCommerceModifier(iI) > 0):
				return true

		return false
						
	def isSpecialistExtraCommerceModifiersDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
			if(objCivicInfo.getSpecialistExtraCommerce(iI) > 0):
				return true

		return false
		
	def isHurrysDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(gc.getNumHurryInfos()):
			if(objCivicInfo.isHurry(iI)):
				return true
		return false
		
	def isSpecialBuildingNotRequiredDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(gc.getNumSpecialBuildingInfos()):
			if(objCivicInfo.isSpecialBuildingNotRequired(iI)):
				return true
		return false
		
	def isSpecialistValidDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(gc.getNumSpecialistInfos()):
			if(objCivicInfo.isSpecialistValid(iI)):
				return true
		return false
		
	def isBuildingHappinessChangeDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(gc.getNumBuildingInfos()):
			if(objCivicInfo.getBuildingHappinessChanges(iI) > 0):
				return true
		return false
		
	def isFeatureHappinessChangeDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(gc.getNumFeatureInfos()):
			if(objCivicInfo.getFeatureHappinessChanges(iI) > 0):
				return true
		return false
		
	def isImprovementYieldChangesDefined(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(gc.getNumImprovementInfos()):
			for iJ in range(YieldTypes.NUM_YIELD_TYPES):
				if(objCivicInfo.getImprovementYieldChanges(iI, iJ) > 0):
					return true
		return false
		
	def isImprovementYieldChangeDefined(self, iCivic, iImprovementType):
		objCivicInfo = gc.getCivicInfo(iCivic)
		
		for iI in range(YieldTypes.NUM_YIELD_TYPES):
			if(objCivicInfo.getImprovementYieldChanges(iImprovementType, iI) > 0):
				return true
		return false

		
	def printCivic(self, iCivic):
		objCivicInfo = gc.getCivicInfo(iCivic)

		szText = ""
		
		szText = appendString(szText,"		<CivicInfo>")
		
		szText = appendString(szText,"			<CivicOptionType>%s</CivicOptionType>" %(gc.getCivicOptionInfo(objCivicInfo.getCivicOptionType()).getType()))		
		szText = appendString(szText,"			<Type>%s</Type>" %(objCivicInfo.getType()))
		szText = appendString(szText,"			<Description>%s</Description>" %(objCivicInfo.getTextKey()))
		szText = appendString(szText,"			<Civilopedia>%s</Civilopedia>" %(objCivicInfo.getCivilopediaKey()))
		szText = appendString(szText,"			<Strategy>%s</Strategy>" %(objCivicInfo.getStrategyKey()))
		szText = appendString(szText,"			<Button>%s</Button>" %(objCivicInfo.getButton()))

		if(objCivicInfo.getTechPrereq() != -1):
			szText = appendString(szText,"			<TechPrereq>%s</TechPrereq>" %(gc.getTechInfo(objCivicInfo.getTechPrereq()).getType()))
		else:
			szText = appendString(szText,"			<TechPrereq>NONE</TechPrereq>")

		szText = appendString(szText,"			<iAnarchyLength>%s</iAnarchyLength>" %(objCivicInfo.getAnarchyLength()))

		if(objCivicInfo.getUpkeep() != -1):
			szText = appendString(szText,"			<Upkeep>%s</Upkeep>" %(gc.getUpkeepInfo(objCivicInfo.getUpkeep()).getType()))
		else:
			szText = appendString(szText,"			<Upkeep>NONE</Upkeep>")

		szText = appendString(szText,"			<iAIWeight>%s</iAIWeight>" %(objCivicInfo.getAIWeight()))
		szText = appendString(szText,"			<iGreatPeopleRateModifier>%s</iGreatPeopleRateModifier>" %(objCivicInfo.getGreatPeopleRateModifier()))
		szText = appendString(szText,"			<iGreatGeneralRateModifier>%s</iGreatGeneralRateModifier>" %(objCivicInfo.getGreatGeneralRateModifier()))
		szText = appendString(szText,"			<iDomesticGreatGeneralRateModifier>%s</iDomesticGreatGeneralRateModifier>" %(objCivicInfo.getDomesticGreatGeneralRateModifier()))
		szText = appendString(szText,"			<iStateReligionGreatPeopleRateModifier>%s</iStateReligionGreatPeopleRateModifier>" %(objCivicInfo.getStateReligionGreatPeopleRateModifier()))
		szText = appendString(szText,"			<iDistanceMaintenanceModifier>%s</iDistanceMaintenanceModifier>" %(objCivicInfo.getDistanceMaintenanceModifier()))
		szText = appendString(szText,"			<iNumCitiesMaintenanceModifier>%s</iNumCitiesMaintenanceModifier>" %(objCivicInfo.getNumCitiesMaintenanceModifier()))
		szText = appendString(szText,"			<iExtraHealth>%s</iExtraHealth>" %(objCivicInfo.getExtraHealth()))
		szText = appendString(szText,"			<iFreeExperience>%s</iFreeExperience>" %(objCivicInfo.getFreeExperience()))
		szText = appendString(szText,"			<iWorkerSpeedModifier>%s</iWorkerSpeedModifier>" %(objCivicInfo.getWorkerSpeedModifier()))
		szText = appendString(szText,"			<iImprovementUpgradeRateModifier>%s</iImprovementUpgradeRateModifier>" %(objCivicInfo.getImprovementUpgradeRateModifier()))
		szText = appendString(szText,"			<iMilitaryProductionModifier>%s</iMilitaryProductionModifier>" %(objCivicInfo.getMilitaryProductionModifier()))
		szText = appendString(szText,"			<iBaseFreeUnits>%s</iBaseFreeUnits>" %(objCivicInfo.getBaseFreeUnits()))
		szText = appendString(szText,"			<iBaseFreeMilitaryUnits>%s</iBaseFreeMilitaryUnits>" %(objCivicInfo.getBaseFreeMilitaryUnits()))
		szText = appendString(szText,"			<iFreeUnitsPopulationPercent>%s</iFreeUnitsPopulationPercent>" %(objCivicInfo.getFreeUnitsPopulationPercent()))
		szText = appendString(szText,"			<iFreeMilitaryUnitsPopulationPercent>%s</iFreeMilitaryUnitsPopulationPercent>" %(objCivicInfo.getFreeMilitaryUnitsPopulationPercent()))
		szText = appendString(szText,"			<iGoldPerUnit>%s</iGoldPerUnit>" %(objCivicInfo.getGoldPerUnit()))
		szText = appendString(szText,"			<iGoldPerMilitaryUnit>%s</iGoldPerMilitaryUnit>" %(objCivicInfo.getGoldPerMilitaryUnit()))
		szText = appendString(szText,"			<iHappyPerMilitaryUnit>%s</iHappyPerMilitaryUnit>" %(objCivicInfo.getHappyPerMilitaryUnit()))

		szText = appendString(szText,"			<bMilitaryFoodProduction>%s</bMilitaryFoodProduction>" %(boolToInt(objCivicInfo.isMilitaryFoodProduction())))

		szText = appendString(szText,"			<iMaxConscript>%s</iMaxConscript>" %(objCivicInfo.getMaxConscript()))
			
		szText = appendString(szText,"			<bNoUnhealthyPopulation>%s</bNoUnhealthyPopulation>" %(boolToInt(objCivicInfo.isNoUnhealthyPopulation())))
		szText = appendString(szText,"			<iExpInBorderModifier>%s</iExpInBorderModifier>" %(objCivicInfo.getExpInBorderModifier()))
		szText = appendString(szText,"			<bBuildingOnlyHealthy>%s</bBuildingOnlyHealthy>" %(boolToInt(objCivicInfo.isBuildingOnlyHealthy())))

		szText = appendString(szText,"			<iLargestCityHappiness>%s</iLargestCityHappiness>" %(objCivicInfo.getLargestCityHappiness()))
		szText = appendString(szText,"			<iWarWearinessModifier>%s</iWarWearinessModifier>" %(objCivicInfo.getWarWearinessModifier()))
		szText = appendString(szText,"			<iFreeSpecialist>%s</iFreeSpecialist>" %(objCivicInfo.getFreeSpecialist()))
		szText = appendString(szText,"			<iTradeRoutes>%s</iTradeRoutes>" %(objCivicInfo.getTradeRoutes()))

		szText = appendString(szText,"			<bNoForeignTrade>%s</bNoForeignTrade>" %(boolToInt(objCivicInfo.isNoForeignTrade())))

		szText = appendString(szText,"			<iCivicPercentAnger>%s</iCivicPercentAnger>" %(objCivicInfo.getCivicPercentAnger()))

		szText = appendString(szText,"			<bStateReligion>%s</bStateReligion>" %(boolToInt(objCivicInfo.isStateReligion())))
		szText = appendString(szText,"			<bNoNonStateReligionSpread>%s</bNoNonStateReligionSpread>" %(boolToInt(objCivicInfo.isNoNonStateReligionSpread())))

		szText = appendString(szText,"			<iStateReligionHappiness>%s</iStateReligionHappiness>" %(objCivicInfo.getStateReligionHappiness()))
		szText = appendString(szText,"			<iNonStateReligionHappiness>%s</iNonStateReligionHappiness>" %(objCivicInfo.getNonStateReligionHappiness()))
		szText = appendString(szText,"			<iStateReligionUnitProductionModifier>%s</iStateReligionUnitProductionModifier>" %(objCivicInfo.getStateReligionUnitProductionModifier()))
		szText = appendString(szText,"			<iStateReligionBuildingProductionModifier>%s</iStateReligionBuildingProductionModifier>" %(objCivicInfo.getStateReligionBuildingProductionModifier()))
		szText = appendString(szText,"			<iStateReligionFreeExperience>%s</iStateReligionFreeExperience>" %(objCivicInfo.getStateReligionFreeExperience()))
		
		if(self.isYieldModifiersDefined(iCivic)):
			szText = appendString(szText,"			<YieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objCivicInfo.getYieldModifier(iI)))
			szText = appendString(szText,"			</YieldModifiers>")
		else:
			szText = appendString(szText,"			<YieldModifiers/>")
		
		if(self.isCapitalYieldModifiersDefined(iCivic)):
			szText = appendString(szText,"			<CapitalYieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objCivicInfo.getCapitalYieldModifier(iI)))
			szText = appendString(szText,"			</CapitalYieldModifiers>")
		else:
			szText = appendString(szText,"			<CapitalYieldModifiers/>")
			
		if(self.isTradeYieldModifiersDefined(iCivic)):
			szText = appendString(szText,"			<TradeYieldModifiers>")
			for iI in range(YieldTypes.NUM_YIELD_TYPES):
				szText = appendString(szText,"				<iYield>%s</iYield>" %(objCivicInfo.getTradeYieldModifier(iI)))
			szText = appendString(szText,"			</TradeYieldModifiers>")
		else:
			szText = appendString(szText,"			<TradeYieldModifiers/>")
			
		if(self.isCommerceModifiersDefined(iCivic)):
			szText = appendString(szText,"			<CommerceModifiers>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objCivicInfo.getCommerceModifier(iI)))
			szText = appendString(szText,"			</CommerceModifiers>")
		else:
			szText = appendString(szText,"			<CommerceModifiers/>")
		
		if(self.isCapitalCommerceModifiersDefined(iCivic)):
			szText = appendString(szText,"			<CapitalCommerceModifiers>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objCivicInfo.getCapitalCommerceModifier(iI)))
			szText = appendString(szText,"			</CapitalCommerceModifiers>")
		else:
			szText = appendString(szText,"			<CapitalCommerceModifiers/>")

		if(self.isSpecialistExtraCommerceModifiersDefined(iCivic)):
			szText = appendString(szText,"			<SpecialistExtraCommerces>")
			for iI in range(CommerceTypes.NUM_COMMERCE_TYPES):
				szText = appendString(szText,"				<iCommerce>%s</iCommerce>" %(objCivicInfo.getSpecialistExtraCommerce(iI)))
			szText = appendString(szText,"			</SpecialistExtraCommerces>")
		else:
			szText = appendString(szText,"			<SpecialistExtraCommerces/>")

		if(self.isHurrysDefined(iCivic)):
			szText = appendString(szText,"			<Hurrys>")
			for iI in range(gc.getNumHurryInfos()):
				if(objCivicInfo.isHurry(iI)):
					szText = appendString(szText,"				<Hurry>")
					szText = appendString(szText,"					<HurryType>%s</HurryType>" %(gc.getHurryInfo(iI).getType()))
					szText = appendString(szText,"					<bHurry>1</bHurry>")
					szText = appendString(szText,"				</Hurry>")
			szText = appendString(szText,"			</Hurrys>")
		else:
			szText = appendString(szText,"			<Hurrys/>")

		if(self.isSpecialBuildingNotRequiredDefined(iCivic)):
			szText = appendString(szText,"			<SpecialBuildingNotRequireds>")
			for iI in range(gc.getNumSpecialBuildingInfos()):
				if(objCivicInfo.isSpecialBuildingNotRequired(iI)):
					szText = appendString(szText,"				<SpecialBuildingNotRequired>")
					szText = appendString(szText,"					<SpecialBuildingType>%s</SpecialBuildingType>" %(gc.getSpecialBuildingInfo(iI).getType()))
					szText = appendString(szText,"					<bNotRequired>1</bNotRequired>")
					szText = appendString(szText,"				</SpecialBuildingNotRequired>")
			szText = appendString(szText,"			</SpecialBuildingNotRequireds>")
		else:
			szText = appendString(szText,"			<SpecialBuildingNotRequireds/>")

		if(self.isSpecialistValidDefined(iCivic)):
			szText = appendString(szText,"			<SpecialistValids>")
			for iI in range(gc.getNumSpecialistInfos()):
				if(objCivicInfo.isSpecialistValid(iI)):
					szText = appendString(szText,"				<SpecialistValid>")
					szText = appendString(szText,"					<SpecialistType>%s</SpecialistType>" %(gc.getSpecialistInfo(iI).getType()))
					szText = appendString(szText,"					<bValid>1</bValid>")
					szText = appendString(szText,"				</SpecialistValid>")
			szText = appendString(szText,"			</SpecialistValids>")
		else:
			szText = appendString(szText,"			<SpecialistValids/>")

		if(self.isBuildingHappinessChangeDefined(iCivic)):
			szText = appendString(szText,"			<BuildingHappinessChanges>")
			for iI in range(gc.getNumBuildingInfos()):
				if(objCivicInfo.getBuildingHappinessChanges(iI) > 0):
					szText = appendString(szText,"				<BuildingHappinessChange>")
					szText = appendString(szText,"					<BuildingType>%s</BuildingType>" %(gc.getBuildingInfo(iI).getType()))
					szText = appendString(szText,"					<iHappinessChange>%s</iHappinessChange>" %(objCivicInfo.getBuildingHappinessChanges(iI)))
					szText = appendString(szText,"				</BuildingHappinessChange>")
			szText = appendString(szText,"			</BuildingHappinessChanges>")
		else:
			szText = appendString(szText,"			<BuildingHappinessChanges/>")

		if(self.isFeatureHappinessChangeDefined(iCivic)):
			szText = appendString(szText,"			<FeatureHappinessChanges>")
			for iI in range(gc.getNumFeatureInfos()):
				if(objCivicInfo.getFeatureHappinessChanges(iI) > 0):
					szText = appendString(szText,"				<FeatureHappinessChange>")
					szText = appendString(szText,"					<FeatureType>%s</FeatureType>" %(gc.getFeatureInfo(iI).getType()))
					szText = appendString(szText,"					<iHappinessChange>%s</iHappinessChange>" %(objCivicInfo.getFeatureHappinessChanges(iI)))
					szText = appendString(szText,"				</FeatureHappinessChange>")
			szText = appendString(szText,"			</FeatureHappinessChanges>")
		else:
			szText = appendString(szText,"			<FeatureHappinessChanges/>")
		
		
		if(self.isImprovementYieldChangesDefined(iCivic)):
			szText = appendString(szText,"			<ImprovementYieldChanges>")
			for iI in range(gc.getNumImprovementInfos()):
				if(self.isImprovementYieldChangeDefined(iCivic, iI) > 0):
					szText = appendString(szText,"				<ImprovementYieldChange>")

					szText = appendString(szText,"					<ImprovementType>%s</ImprovementType>" %(gc.getImprovementInfo(iI).getType()))
					szText = appendString(szText,"					<ImprovementYields>")
					for iJ in range(YieldTypes.NUM_YIELD_TYPES):
						szText = appendString(szText,"						<iYield>%s</iYield>" %(objCivicInfo.getImprovementYieldChanges(iI, iJ)))
					szText = appendString(szText,"					</ImprovementYields>")
					szText = appendString(szText,"				</ImprovementYieldChange>")
			szText = appendString(szText,"			</ImprovementYieldChanges>")
		else:
			szText = appendString(szText,"			<ImprovementYieldChanges/>")
		

		if(len(objCivicInfo.pyGetWeLoveTheKing()) > 0):
			szText = appendString(szText,"			<WeLoveTheKing>%s</WeLoveTheKing>" %(objCivicInfo.pyGetWeLoveTheKingKey()))
		else:
			szText = appendString(szText,"			<WeLoveTheKing/>")
			
		szText = appendString(szText,"		</CivicInfo>")
			
		return szText

						
	def printCivics(self):	
	
		strSavePath = ""
		strFileSavePath = ""
		strModPath = ""
		strModAssetPath = ""
		strModAssetSavePath = ""
		strModAssetPath = ""
		
		if(os.access(CvPath.userActiveModDir,os.F_OK)):
			strModPath = CvPath.userActiveModDir
		elif(os.access(CvPath.installActiveModDir,os.F_OK)):
			strModPath = CvPath.installActiveModDir
		else:
			self.dataSavePopup(false)
			return
			
		strSavePath = "%s\%s" %(strModPath,g_strSaveDirectoryLocation)
		strModAssetPath = "%s\\Assets\\" %(strModPath)
		
		if(g_bCreateAssetHierarchy):
			strSavePath += "\Assets\XML\GameInfo" 

		strFileSavePath = "%s\%s" %(strSavePath, "CIV4CivicInfos.xml")

		try:
			if(os.access(strSavePath,os.F_OK)):
				if(os.access(strFileSavePath,os.F_OK)):
					os.remove(strFileSavePath)
				os.removedirs(strSavePath)
		except:
			pass
			
		if(not os.access(strSavePath,os.F_OK)):
			os.makedirs(strSavePath)

							
		szText = "<?xml version=\"1.0\"?>"
		szText = appendString(szText,"<!-- Created by Tech Civilizeditor %s by TheLopez-->" %(editorVersion()))
		szText = appendString(szText,"<Civ4CivicInfos xmlns=\"x-schema:CIV4GameInfoSchema.xml\">")
		szText = appendString(szText,"<!-- Sid Meier's Civilization 4 -->")
		szText = appendString(szText,"<!-- Copyright Firaxis Games 2005 -->")
		szText = appendString(szText,"<!-- -->")
		szText = appendString(szText,"<!-- Civic Infos -->")
		szText = appendString(szText,"	<CivicInfos>")
				
		for iCivic in range(gc.getNumCivicInfos()):

			if(gc.getCivicInfo(iCivic).isDeleted()):
				continue

			szText = appendString(szText,self.printCivic(iCivic))
			
						
		szText = appendString(szText,"	</CivicInfos>")
		szText = appendString(szText,"</Civ4CivicInfos>")

			
		fd = os.open(strFileSavePath, os.O_CREAT)
		os.close(fd)

		fd = os.open(strFileSavePath, os.O_RDWR)
		os.write(fd, szText)
		os.close(fd)
		
		if(g_bSaveChangesInEditorAssetsDirectory):
			strModAssetPath = "%s\%s" %(strModPath,"\Assets\XML\GameInfo")
			strModAssetSavePath = "%s\%s" %(strModPath, "\Assets\XML\GameInfo\CIV4CivicInfos.xml")
			try:
				if(os.access(strModAssetPath,os.F_OK)):
					if(os.access(strModAssetSavePath,os.F_OK)):
						os.remove(strModAssetSavePath)
			except:
				pass
			
			if(not os.access(strModAssetPath,os.F_OK)):
				os.makedirs(strModAssetPath)

			fd = os.open(strModAssetSavePath, os.O_CREAT)
			os.close(fd)

			fd = os.open(strModAssetSavePath, os.O_RDWR)
			os.write(fd, szText)
			os.close(fd)
	

